package com.itboye.mengwu.app.ui.mymeng;

import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.SPUtils;
import com.itboye.mengwu.R;
import com.itboye.mengwu.data.model.TieZiBaoHanReply;
import com.itboye.mengwu.data.model.WithdrawalsBean;
import com.itboye.mengwu.data.presenter.LiShiTiXianPresenter;
import com.itboye.mengwu.data.presenter.TieZiPresenter;
import com.itboye.mengwu.widget.XListView;
import com.itboye.mengwu.widget.XListView.IXListViewListener;
import com.itboye.shopcar_adapter.HistoryAdapter;

/***
 * 历史提现
 * 
 * @author tiantian
 * 
 */
public class HistoryWithdrawalsActivity extends BaseActivity implements
		Observer, IXListViewListener {
	private XListView lsitviewHistory;
	private HistoryAdapter adapter;
	private ArrayList<WithdrawalsBean> arrayList = new ArrayList<WithdrawalsBean>();
	private WithdrawalsBean bean;
	private LiShiTiXianPresenter presenter;
	private String uid;
	private int pageNo = 1;
	private ImageView back;

	private TextView txt_title;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_history;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub

		txt_title.setText("提现记录");
		lsitviewHistory.setXListViewListener(this);
		lsitviewHistory.setPullLoadEnable(true);
		lsitviewHistory.setPullRefreshEnable(true);
		presenter = new LiShiTiXianPresenter(this);
		uid = SPUtils.get(HistoryWithdrawalsActivity.this, null,
				SpPublicParams.UID, "") + "";
		bean = new WithdrawalsBean();
		bean.setUid(uid);
		presenter.getInfo(bean);
		back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});

	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == LiShiTiXianPresenter.LiSHiTiXIan_success) {
				adapter = new HistoryAdapter(this,
						((WithdrawalsBean) entity.getData()).getList());

				lsitviewHistory.setAdapter(adapter);

				try {
					// ByAlert.alert("解析出错");

					adapter.notifyDataSetChanged();
				} catch (Exception e) {
					// TODO: handle exception
					ByAlert.alert("系统异常");
				}
				stopLoad();
			}
		}
	}

	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		pageNo = 1;
		presenter.getInfo(bean);
	}

	@Override
	public void onLoadMore() {
		// TODO Auto-generated method stub
		pageNo++;
		presenter.getInfo(bean);
	}

	public void stopLoad() {
		lsitviewHistory.stopLoadMore();
		lsitviewHistory.stopRefresh();
	}

}
